home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / MosaicSRC / libwww2 / HTInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  21.7 KB  |  637 lines

  1. #include "HTInit.h"
  2.  
  3. #include "HTML.h"
  4. #include "HTPlain.h"
  5. #include "HTMosaicHTML.h"
  6. #include "HTMLGen.h"
  7. #include "HTFile.h"
  8. #include "HTFormat.h"
  9. #include "HTMIME.h"
  10. #include "HTWSRC.h"
  11.  
  12. #include "tcp.h"
  13. #include "HTUtils.h"
  14.  
  15. int HTLoadTypesConfigFile (char *fn);
  16.  
  17. /* #define TRACE 1 */
  18.  
  19. /* Reread config files. */
  20. PUBLIC void HTReInit NOARGS
  21. {
  22.   if (HTPresentations)
  23.     {
  24.       HTList_delete (HTPresentations);
  25.       HTPresentations = 0;
  26.     }
  27.   HTFormatInit ();
  28.  
  29.   if (HTSuffixes)
  30.     {
  31.       HTList_delete (HTSuffixes);
  32.       HTSuffixes = 0;
  33.     }
  34.   HTFileInit ();
  35.  
  36.   return;
  37. }
  38.  
  39. PUBLIC void HTFormatInit NOARGS
  40. {
  41.   extern int use_default_type_map;
  42.   extern char *global_type_map;
  43.   extern char *personal_type_map;
  44.   extern int have_hdf;
  45.  
  46.   /* Conversions aren't customizable. */
  47.   HTSetConversion("www/mime",  "*", HTMIMEConvert, 1.0, 0.0, 0.0);
  48.  
  49.   /* Wonder what HTML will end up as? */
  50.   HTSetConversion("text/html", "www/present", HTMosaicHTMLPresent, 1.0, 0.0, 0.0);
  51.   HTSetConversion("text/x-html", "www/present", HTMosaicHTMLPresent, 1.0, 0.0, 0.0);
  52.   HTSetConversion("application/html", "www/present", HTMosaicHTMLPresent, 1.0, 0.0, 0.0);
  53.   HTSetConversion("application/x-html", "www/present", HTMosaicHTMLPresent, 1.0, 0.0, 0.0);
  54.  
  55.   HTSetConversion("text/plain", "www/present", HTPlainPresent,  1.0, 0.0, 0.0);
  56.   HTSetConversion("application/x-wais-source", "*", HTWSRCConvert, 1.0, 0.0, 0.0);
  57.  
  58.   /* These should override everything else. */
  59.   HTLoadTypesConfigFile (personal_type_map);
  60.  
  61.   /* These should override the default types as necessary. */
  62.   HTLoadTypesConfigFile (global_type_map);
  63.  
  64.   /* These should always be installed if we have internal support;
  65.      can be overridden by users. */
  66.   if (have_hdf)
  67.     {
  68.       HTSetPresentation("application/x-hdf",      "mosaic-internal-reference",
  69.             1.0, 3.0, 0.0);
  70.       HTSetPresentation("application/x-netcdf",   "mosaic-internal-reference",
  71.             1.0, 3.0, 0.0);
  72.       /* Jumping the gun, but still... */
  73.       HTSetPresentation("application/hdf",      "mosaic-internal-reference",
  74.             1.0, 3.0, 0.0);
  75.       HTSetPresentation("application/netcdf",   "mosaic-internal-reference",
  76.             1.0, 3.0, 0.0);
  77.     }
  78.  
  79.   if (use_default_type_map)
  80.     {
  81. #if defined (_AMIGA)
  82.      /* It is an amiga, use multiview for just about everything */
  83.       /* For the amiga @ at the end of the line will be replaced
  84.         by pubscreen="name of screen mosaic is running on" */
  85.       HTSetPresentation("audio/basic","rx rexx:soxaudio %s @",1.0,3.0,0.0);
  86.       HTSetPresentation("audio/x-aiff","rx rexx:soxaudio %s @",1.0,3.0,0.0);
  87.       HTSetPresentation("image/gif","sys:utilities/Multiview %s @",1.0,3.0,0.0);
  88.       HTSetPresentation("image/tiff","sys:utilities/Multiview %s @",1.0,3.0,0.0);
  89.       HTSetPresentation("image/jpeg","sys:utilities/Multiview %s @",1.0,3.0,0.0);
  90.       HTSetPresentation("image/x-rgb","sys:utilities/Multiview %s @",1.0,3.0,0.0);
  91.       HTSetPresentation("image/rgb","sys:utilities/Multiview %s @",1.0,3.0,0.0);
  92.       HTSetPresentation("image/x-iff",   "sys:utilities/Multiview %s @",1.0,3.0,0.0);
  93.       HTSetPresentation("image/x-ilbm", "sys:utilities/Multiview %s @",1.0,3.0,0.0);
  94.       HTSetPresentation("video/x-anim", "sys:utilities/Multiview %s @",1.0,3.0,0.0);
  95.       HTSetPresentation("video/x-cdxl", "sys:utilities/Multiview %s @",1.0,3.0,0.0);
  96.       HTSetPresentation("audio/x-8svx", "sys:utilities/Multiview %s @",1.0,3.0,0.0);
  97.       HTSetPresentation("text/x-aguide", "sys:utilities/Multiview %s @",1.0,3.0,0.0);
  98.       HTSetPresentation("music/x-mod", "rx rexx:playmod.rexx %s ",1.0,3.0,0.0);
  99.       HTSetPresentation("image/x-portable-anymap","sys:utilities/Multiview %s @",1.0,3.0,0.0);
  100.       HTSetPresentation("image/x-portable-bitmap","sys:utilities/Multiview %s @",1.0,3.0,0.0);
  101.       HTSetPresentation("image/x-portable-graymap","sys:utilities/Multiview %s @",1.0,3.0,0.0);
  102.       HTSetPresentation("image/x-portable-pixmap","sys:utilities/Multiview %s @",1.0,3.0,0.0);
  103.       HTSetPresentation("image/x-xbitmap","sys:utilities/Multiview %s @",1.0,3.0,0.0);
  104.       HTSetPresentation("image/x-xpixmap","sys:utilities/Multiview %s @",1.0,3.0,0.0); /* ?? */
  105.  
  106. #else
  107. #if defined(__sgi)
  108.       HTSetPresentation("audio/basic", "sfplay %s", 1.0, 3.0, 0.0);
  109.       HTSetPresentation("audio/x-aiff", "sfplay %s", 1.0, 3.0, 0.0);
  110. #else /* not __sgi */
  111. #if defined(ultrix) || defined(__alpha)
  112.       HTSetPresentation("audio/basic", "aplay %s", 1.0, 3.0, 0.0);
  113.       HTSetPresentation("audio/x-aiff", "aplay %s", 1.0, 3.0, 0.0);
  114. #else /* not ultrix or __alpha */
  115.       HTSetPresentation("audio/basic", "showaudio %s", 1.0, 3.0, 0.0);
  116.       HTSetPresentation("audio/x-aiff", "showaudio %s", 1.0, 3.0, 0.0);
  117. #endif /* not ultrix or __alpha */
  118. #endif /* not __sgi */
  119.  
  120.       HTSetPresentation("image/gif", "xv %s", 1.0, 3.0, 0.0);
  121.       HTSetPresentation("image/jpeg", "xv %s", 1.0, 3.0, 0.0);
  122.       HTSetPresentation("image/tiff", "xv %s", 1.0, 3.0, 0.0);
  123.       HTSetPresentation("image/x-portable-anymap", "xv %s", 1.0, 3.0, 0.0);
  124.       HTSetPresentation("image/x-portable-bitmap", "xv %s", 1.0, 3.0, 0.0);
  125.       HTSetPresentation("image/x-portable-graymap", "xv %s", 1.0, 3.0, 0.0);
  126.       HTSetPresentation("image/x-portable-pixmap", "xv %s", 1.0, 3.0, 0.0);
  127.       HTSetPresentation("image/x-rgb", "xv %s", 1.0, 3.0, 0.0);
  128.       HTSetPresentation("image/rgb", "xv %s", 1.0, 3.0, 0.0);
  129.       HTSetPresentation("image/x-xbitmap", "xv %s", 1.0, 3.0, 0.0);
  130.       HTSetPresentation("image/x-xpixmap", "xv %s", 1.0, 3.0, 0.0); /* ?? */
  131.  
  132.       HTSetPresentation("image/xwd", "xwud -in %s", 1.0, 3.0, 0.0);
  133.       HTSetPresentation("image/x-xwd", "xwud -in %s", 1.0, 3.0, 0.0);
  134.       HTSetPresentation("image/x-xwindowdump", "xwud -in %s", 1.0, 3.0, 0.0);
  135.  
  136.       HTSetPresentation("video/mpeg", "mpeg_play %s", 1.0, 3.0, 0.0);
  137. #ifdef __sgi
  138.       HTSetPresentation("video/quicktime", "movieplayer -f %s", 1.0, 3.0, 0.0); /* sgi */
  139.       HTSetPresentation("video/x-sgi-movie", "movieplayer -f %s", 1.0, 3.0, 0.0); /* sgi */
  140. #endif
  141.  
  142.       HTSetPresentation("application/postscript", "ghostview %s", 1.0, 3.0, 0.0);
  143.       HTSetPresentation("application/x-dvi", "xdvi %s", 1.0, 3.0, 0.0);
  144.  
  145.       HTSetPresentation("message/rfc822",
  146.             "xterm -e metamail %s", 1.0, 3.0, 0.0);
  147. #endif    /* ! amiga */
  148.       HTSetPresentation("application/x-latex", "mosaic-internal-present", 1.0, 3.0, 0.0);
  149.       HTSetPresentation("application/x-tex", "mosaic-internal-present", 1.0, 3.0, 0.0);
  150.       HTSetPresentation("application/x-texinfo", "mosaic-internal-present", 1.0, 3.0, 0.0);
  151.       HTSetPresentation("application/x-troff", "mosaic-internal-present", 1.0, 3.0, 0.0);
  152.       HTSetPresentation("application/x-troff-man", "mosaic-internal-present", 1.0, 3.0, 0.0);
  153.       HTSetPresentation("application/x-troff-me", "mosaic-internal-present", 1.0, 3.0, 0.0);
  154.       HTSetPresentation("application/x-troff-ms", "mosaic-internal-present", 1.0, 3.0, 0.0);
  155.       HTSetPresentation("text/richtext", "mosaic-internal-present", 1.0, 3.0, 0.0);
  156.       HTSetPresentation("text/tab-separated-values", "mosaic-internal-present", 1.0, 3.0, 0.0);
  157.       HTSetPresentation("text/x-setext", "mosaic-internal-present", 1.0, 3.0, 0.0);
  158.     }
  159.  
  160.   /* Fallthrough clauses. */
  161.   HTSetPresentation ("*/*", "mosaic-internal-dump", 1.0, 3.0, 0.0);
  162.   HTSetPresentation ("*", "mosaic-internal-dump", 1.0, 3.0, 0.0);
  163. }
  164.  
  165.  
  166. /* Some of the following is taken from: */
  167.  
  168. /*
  169. Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  170.  
  171. Permission to use, copy, modify, and distribute this material
  172. for any purpose and without fee is hereby granted, provided
  173. that the above copyright notice and this permission notice
  174. appear in all copies, and that the name of Bellcore not be
  175. used in advertising or publicity pertaining to this
  176. material without the specific, prior written permission
  177. of an authorized representative of Bellcore.  BELLCORE
  178. MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
  179. OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",
  180. WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  181. */
  182. /******************************************************
  183.     Metamail -- A tool to help diverse mail readers
  184.         cope with diverse multimedia mail formats.
  185.  
  186.     Author:  Nathaniel S. Borenstein, Bellcore
  187.  
  188.  ******************************************************* */
  189.  
  190. struct MailcapEntry {
  191.     char *contenttype;
  192.     char *command;
  193.     int needsterminal;
  194. };
  195.  
  196. #define LINE_BUF_SIZE        2000
  197.  
  198. static char *GetCommand(char *s, char **t)
  199. {
  200.     char *s2;
  201.     int quoted = 0;
  202.     /* marca -- added + 1 for error case -- oct 24, 1993. */
  203.     s2 = malloc(strlen(s)*2 + 1); /* absolute max, if all % signs */
  204.     *t = s2;
  205.     while (s && *s) {
  206.     if (quoted) {
  207.         if (*s == '%') *s2++ = '%'; /* Quote through next level, ugh! */
  208.  
  209.         *s2++ = *s++;
  210.         quoted = 0;
  211.     } else {
  212.         if (*s == ';') {
  213.         *s2 = 0;
  214.         return(++s);
  215.         }
  216.         if (*s == '\\') {
  217.         quoted = 1;
  218.         ++s;
  219.         } else {
  220.         *s2++ = *s++;
  221.         }
  222.     }
  223.     }
  224.     *s2 = 0;
  225.     return(NULL);
  226. }
  227.  
  228. static char *Cleanse(char *s) /* no leading or trailing space, all lower case */
  229. {
  230.     char *tmp, *news;
  231.  
  232.     /* strip leading white space */
  233.     while (*s && isspace((unsigned char) *s)) ++s;
  234.     news = s;
  235.     /* put in lower case */
  236.     for (tmp=s; *tmp; ++tmp) {
  237.       *tmp = TOLOWER ((unsigned char)*tmp);
  238.     }
  239.     /* strip trailing white space */
  240.     while (*--tmp && isspace((unsigned char) *tmp)) *tmp = 0;
  241.     return(news);
  242. }
  243.  
  244. static ProcessMailcapEntry(FILE *fp, struct MailcapEntry *mc)
  245. {
  246.     int rawentryalloc = 2000, len;
  247.     char *rawentry, *s, *t, *LineBuf;
  248.  
  249.     LineBuf = malloc(LINE_BUF_SIZE);
  250.     rawentry = malloc(1 + rawentryalloc);
  251.     *rawentry = 0;
  252.     while (fgets(LineBuf, LINE_BUF_SIZE, fp)) {
  253.     if (LineBuf[0] == '#') continue;
  254.     len = strlen(LineBuf);
  255.     if (LineBuf[len-1] == '\n') LineBuf[--len] = 0;
  256.     if ((len + strlen(rawentry)) > rawentryalloc) {
  257.         rawentryalloc += 2000;
  258.         rawentry = realloc(rawentry, rawentryalloc+1);
  259.     }
  260.     if (len > 0 && LineBuf[len-1] == '\\') {
  261.         LineBuf[len-1] = 0;
  262.         strcat(rawentry, LineBuf);
  263.     } else {
  264.         strcat(rawentry, LineBuf);
  265.         break;
  266.     }
  267.     }
  268.     free(LineBuf);
  269.     for (s=rawentry; *s && isspace((unsigned char) *s); ++s) ;
  270.     if (!*s) {
  271.     /* totally blank entry -- quietly ignore */
  272.     free(rawentry);
  273.     return(0);
  274.     }
  275.     s = strchr(rawentry, ';');
  276.     if (!s) {
  277.       if (TRACE)
  278.     fprintf(stderr, "Ignoring invalid mailcap entry: %s\n", rawentry);
  279.       free(rawentry);
  280.       return(0);
  281.     }
  282.     *s++ = 0;
  283.     mc->needsterminal = 0;
  284.     mc->contenttype = malloc(1+strlen(rawentry));
  285.     strcpy(mc->contenttype, rawentry);
  286.  
  287.     t = GetCommand(s, &mc->command);
  288.     if (!t) {
  289.     free(rawentry);
  290.     goto do_presentation;
  291.     }
  292.     while (s && *s && isspace((unsigned char) *s)) ++s;
  293.     s = t;
  294.     while (s) {
  295.     char *arg, *eq;
  296.  
  297.     t = GetCommand(s, &arg);
  298.     eq = strchr(arg, '=');
  299.     if (eq) *eq++ = 0;
  300.     /* Error check added by marca, oct 24 1993. */
  301.     if (arg && *arg)
  302.       arg = Cleanse(arg);
  303.     if (!strcmp(arg, "needsterminal")) {
  304.         mc->needsterminal = 1;
  305.     }
  306.     s = t;
  307.     }
  308.  
  309.     free(rawentry);
  310.   do_presentation:
  311.     HTSetPresentation(mc->contenttype, mc->command, 1.0, 3.0, 0.0);
  312.     return(1);
  313. }
  314.  
  315.  
  316. static ProcessMailcapFile(char *file)
  317. {
  318.     struct MailcapEntry mc;
  319.     FILE *fp;
  320.  
  321.     if (TRACE)
  322.       fprintf (stderr, "Loading types config file '%s'\n",
  323.            file);
  324.  
  325.     fp = fopen(file, "r");
  326.  
  327.     while (fp && !feof(fp)) {
  328.     ProcessMailcapEntry(fp, &mc);
  329.     }
  330.     if (fp) fclose(fp);
  331.     return(-1);
  332. }
  333.  
  334.  
  335.  
  336. int HTLoadTypesConfigFile (char *fn)
  337. {
  338.   return ProcessMailcapFile (fn);
  339. }
  340.  
  341.  
  342.  
  343.  
  344. /* ------------------------------------------------------------------------ */
  345. /* ------------------------------------------------------------------------ */
  346. /* ------------------------------------------------------------------------ */
  347.  
  348. /*    Define a basic set of suffixes
  349. **    ------------------------------
  350. **
  351. **    The LAST suffix for a type is that used for temporary files
  352. **    of that type.
  353. **    The quality is an apriori bias as to whether the file should be
  354. **    used.  Not that different suffixes can be used to represent files
  355. **    which are of the same format but are originals or regenerated,
  356. **    with different values.
  357. */
  358.  
  359. PUBLIC void HTFileInit NOARGS
  360. {
  361.   extern int use_default_extension_map;
  362.   extern char *global_extension_map;
  363.   extern char *personal_extension_map;
  364.  
  365.   if (use_default_extension_map)
  366.     {
  367.       if (TRACE)
  368.     fprintf (stderr, "@@@ Using default extension map\n");
  369.  
  370.       HTSetSuffix(".uu",        "application/octet-stream", "binary", 1.0); /* xtra */
  371.       HTSetSuffix(".saveme",    "application/octet-stream", "binary", 1.0); /* xtra */
  372.       HTSetSuffix(".dump",      "application/octet-stream", "binary", 1.0); /* xtra */
  373.       HTSetSuffix(".hqx",       "application/octet-stream", "binary", 1.0);
  374.       HTSetSuffix(".arc",       "application/octet-stream", "binary", 1.0);
  375.       HTSetSuffix(".o",         "application/octet-stream", "binary", 1.0);
  376.       HTSetSuffix(".a",         "application/octet-stream", "binary", 1.0);
  377.       HTSetSuffix(".bin",       "application/octet-stream", "binary", 1.0);
  378.       HTSetSuffix(".exe",       "application/octet-stream", "binary", 1.0);
  379.       /* Temporary only. */
  380.       HTSetSuffix(".z",         "application/octet-stream", "binary", 1.0);
  381.       HTSetSuffix(".gz",        "application/octet-stream", "binary", 1.0);
  382.  
  383.       HTSetSuffix(".oda",       "application/oda", "binary", 1.0);
  384.  
  385.       HTSetSuffix(".pdf",       "application/pdf", "binary", 1.0);
  386.  
  387.       HTSetSuffix(".eps",       "application/postscript", "binary", 1.0);
  388.       HTSetSuffix(".ai",        "application/postscript", "binary", 1.0);
  389.       HTSetSuffix(".ps",        "application/postscript", "binary", 1.0);
  390.  
  391.       HTSetSuffix(".rtf",       "application/rtf", "binary", 1.0);
  392.  
  393.       HTSetSuffix(".dvi","application/x-dvi", "binary", 1.0);
  394.  
  395.       HTSetSuffix(".hdf","application/x-hdf", "binary", 1.0);
  396.  
  397.       HTSetSuffix(".latex", "application/x-latex", "binary", 1.0);
  398.  
  399.       HTSetSuffix(".cdf","application/x-netcdf", "binary", 1.0);
  400.       HTSetSuffix(".nc","application/x-netcdf", "binary", 1.0);
  401.  
  402.       HTSetSuffix(".tex",  "application/x-tex", "binary", 1.0);
  403.  
  404.       HTSetSuffix(".texinfo",       "application/x-texinfo",    "binary", 1.0);
  405.       HTSetSuffix(".texi",          "application/x-texinfo",    "binary", 1.0);
  406.  
  407.       HTSetSuffix(".t",    "application/x-troff", "binary", 1.0);
  408.       HTSetSuffix(".tr",   "application/x-troff", "binary", 1.0);
  409.       HTSetSuffix(".roff", "application/x-troff", "binary", 1.0);
  410.       HTSetSuffix(".man",  "application/x-troff-man", "binary", 1.0);
  411.       HTSetSuffix(".me",   "application/x-troff-me", "binary", 1.0);
  412.       HTSetSuffix(".ms",   "application/x-troff-ms", "binary", 1.0);
  413.  
  414.       HTSetSuffix(".src",       "application/x-wais-source", "binary", 1.0);
  415.       HTSetSuffix(".wsrc",      "application/x-wais-source", "binary", 1.0); /* xtra */
  416.  
  417.       HTSetSuffix(".zip", "application/zip", "binary", 1.0);
  418.  
  419.       HTSetSuffix(".bcpio",   "application/x-bcpio", "binary", 1.0);
  420.       HTSetSuffix(".cpio",    "application/x-cpio", "binary", 1.0);
  421.       HTSetSuffix(".gtar",    "application/x-gtar", "binary", 1.0);
  422.       HTSetSuffix(".shar",    "application/x-shar", "binary", 1.0);
  423.       HTSetSuffix(".sh",      "application/x-shar", "binary", 1.0); /* xtra */
  424.       HTSetSuffix(".sv4cpio", "application/x-sv4cpio", "binary", 1.0);
  425.       HTSetSuffix(".sv4crc",  "application/x-sv4crc", "binary", 1.0);
  426.       HTSetSuffix(".tar",     "application/x-tar", "binary", 1.0);
  427.       HTSetSuffix(".ustar",   "application/x-ustar", "binary", 1.0);
  428.  
  429.       HTSetSuffix(".snd",  "audio/basic", "binary", 1.0);
  430.       HTSetSuffix(".au",   "audio/basic", "binary", 1.0);
  431.       HTSetSuffix(".aifc", "audio/x-aiff", "binary", 1.0);
  432.       HTSetSuffix(".aif",  "audio/x-aiff", "binary", 1.0);
  433.       HTSetSuffix(".aiff", "audio/x-aiff", "binary", 1.0);
  434.       HTSetSuffix(".wav",  "audio/x-wav", "binary", 1.0);
  435.  
  436.       HTSetSuffix(".gif", "image/gif", "binary", 1.0);
  437.  
  438.       HTSetSuffix(".ief", "image/ief", "binary", 1.0);
  439.  
  440.       HTSetSuffix(".jfif","image/jpeg", "binary", 1.0); /* xtra */
  441.       HTSetSuffix(".jfif-tbnl","image/jpeg", "binary", 1.0); /* xtra */
  442.       HTSetSuffix(".jpe", "image/jpeg", "binary", 1.0);
  443.       HTSetSuffix(".jpg", "image/jpeg", "binary", 1.0);
  444.       HTSetSuffix(".jpeg","image/jpeg", "binary", 1.0);
  445.  
  446.       HTSetSuffix(".tif", "image/tiff", "binary", 1.0);
  447.       HTSetSuffix(".tiff","image/tiff", "binary", 1.0);
  448.  
  449.       HTSetSuffix(".ras", "image/x-cmu-rast", "binary", 1.0);
  450.       HTSetSuffix(".pnm", "image/x-portable-anymap", "binary", 1.0);
  451.       HTSetSuffix(".pbm", "image/x-portable-bitmap", "binary", 1.0);
  452.       HTSetSuffix(".pgm", "image/x-portable-graymap", "binary", 1.0);
  453.       HTSetSuffix(".ppm", "image/x-portable-pixmap", "binary", 1.0);
  454.       HTSetSuffix(".rgb", "image/x-rgb", "binary", 1.0);
  455.       HTSetSuffix(".xbm", "image/x-xbitmap", "binary", 1.0);
  456.       HTSetSuffix(".xpm", "image/x-xpixmap", "binary", 1.0);
  457.       HTSetSuffix(".xwd", "image/x-xwindowdump", "binary", 1.0);
  458.  
  459.       HTSetSuffix(".htm",   "text/html", "binary", 1.0);
  460.       HTSetSuffix(".html",  "text/html", "binary", 1.0);
  461.  
  462.       HTSetSuffix(".text",     "text/plain", "binary", 1.0);
  463.       HTSetSuffix(".c",        "text/plain", "binary", 1.0);
  464.       HTSetSuffix(".cc",       "text/plain", "binary", 1.0);
  465.       HTSetSuffix(".c++",      "text/plain", "binary", 1.0);
  466.       HTSetSuffix(".h",        "text/plain", "binary", 1.0);
  467.       HTSetSuffix(".pl",       "text/plain", "binary", 1.0);
  468.       HTSetSuffix(".txt",      "text/plain", "binary", 1.0);
  469.  
  470.       HTSetSuffix(".rtx", "text/richtext", "binary", 1.0); /* MIME richtext */
  471.       HTSetSuffix(".tsv", "text/tab-separated-values", "binary", 1.0);
  472.       HTSetSuffix(".etx", "text/x-setext", "binary", 1.0);
  473.  
  474.       HTSetSuffix(".mpg",  "video/mpeg", "binary", 1.0);
  475.       HTSetSuffix(".mpe",  "video/mpeg", "binary", 1.0);
  476.       HTSetSuffix(".mpeg", "video/mpeg", "binary", 1.0);
  477.  
  478.       HTSetSuffix(".mov", "video/quicktime", "binary", 1.0);
  479.       HTSetSuffix(".qt",  "video/quicktime", "binary", 1.0);
  480.  
  481.       HTSetSuffix(".avi", "video/x-msvideo", "binary", 1.0);
  482.  
  483.       HTSetSuffix(".movie", "video/x-sgi-movie", "binary", 1.0);
  484.       HTSetSuffix(".mv",    "video/x-sgi-movie", "binary", 1.0);
  485.  
  486.       HTSetSuffix(".mime", "message/rfc822", "binary", 1.0);
  487. #ifdef _AMIGA
  488.   HTSetSuffix(".LHA",   "application/octet-stream", "binary", 1.0);
  489.   HTSetSuffix(".lha",   "application/octet-stream", "binary", 1.0);
  490.   HTSetSuffix(".LZH",   "application/octet-stream", "binary", 1.0);
  491.   HTSetSuffix(".lzh",   "application/octet-stream", "binary", 1.0);
  492.   HTSetSuffix(".dms",   "application/octet-stream", "binary", 1.0);
  493.   HTSetSuffix(".DMS",   "application/octet-stream", "binary", 1.0);
  494.   HTSetSuffix(".zoo",   "application/octet-stream", "binary", 1.0);
  495.   HTSetSuffix(".ZOO",   "application/octet-stream", "binary", 1.0);
  496.   HTSetSuffix(".zip",   "application/octet-stream", "binary", 1.0);
  497.   HTSetSuffix(".ZIP",   "application/octet-stream", "binary", 1.0);
  498.  
  499.    HTSetSuffix(".IFF",  "image/x-iff", "binary", (float)1.0);
  500.    HTSetSuffix(".iff",  "image/x-iff", "binary", (float)1.0);
  501.  
  502.    HTSetSuffix(".ILBM", "image/x-ilbm", "binary", (float)1.0);
  503.    HTSetSuffix(".ilbm", "image/x-ilbm", "binary", (float)1.0);
  504.  
  505.    HTSetSuffix(".ANIM", "video/x-anim", "binary", (float)1.0);
  506.    HTSetSuffix(".anim", "video/x-anim", "binary", (float)1.0);
  507.  
  508.    HTSetSuffix(".CDXL", "video/x-cdxl", "binary", (float)1.0);
  509.    HTSetSuffix(".cdxl", "video/x-cdxl", "binary", (float)1.0);
  510.    HTSetSuffix(".XL",   "video/x-cdxl", "binary", (float)1.0);
  511.    HTSetSuffix(".Xl",   "video/x-cdxl", "binary", (float)1.0);
  512.    HTSetSuffix(".xl",   "video/x-cdxl", "binary", (float)1.0);
  513.  
  514.    HTSetSuffix(".8SVX", "audio/x-8svx", "binary", (float)1.0);
  515.    HTSetSuffix(".8svx", "audio/x-8svx", "binary", (float)1.0);
  516.  
  517.    HTSetSuffix(".GUIDE", "text/x-aguide", "binary", (float)1.0);
  518.    HTSetSuffix(".guide", "text/x-aguide", "binary", (float)1.0);
  519.  
  520.    HTSetSuffix(".MOD", "music/x-mod", "binary", (float)1.0);
  521.    HTSetSuffix(".Mod", "music/x-mod", "binary", (float)1.0);
  522.    HTSetSuffix(".mod", "music/x-mod", "binary", (float)1.0);
  523. #endif
  524.     }
  525.  
  526.   /* These should override the default extensions as necessary. */
  527.   HTLoadExtensionsConfigFile (global_extension_map);
  528.  
  529.   /* These should override everything else. */
  530.   HTLoadExtensionsConfigFile (personal_extension_map);
  531. }
  532.  
  533.  
  534.  
  535. /* -------------------- Extension config file reading --------------------- */
  536.  
  537. /* The following is lifted from NCSA httpd 1.0a1, by Rob McCool;
  538.    NCSA httpd is in the public domain, as is this code. */
  539.  
  540. #define MAX_STRING_LEN 256
  541.  
  542. static int getline(char *s, int n, FILE *f)
  543. {
  544.   register int i=0;
  545.  
  546.   while(1)
  547.     {
  548.       s[i] = (char)fgetc(f);
  549.  
  550.       if(s[i] == CR)
  551.     s[i] = fgetc(f);
  552.  
  553.       if((s[i] == EOF) || (s[i] == LF) || (i == (n-1)))
  554.     {
  555.       s[i] = '\0';
  556.       return (feof(f) ? 1 : 0);
  557.     }
  558.       ++i;
  559.     }
  560.  
  561.   /* NOTREACHED */
  562. }
  563.  
  564. static void getword(char *word, char *line, char stop, char stop2)
  565. {
  566.   int x = 0, y;
  567.  
  568.   for (x = 0; line[x] && line[x] != stop && line[x] != stop2; x++)
  569.     {
  570.       word[x] = line[x];
  571.     }
  572.  
  573.   word[x] = '\0';
  574.   if (line[x])
  575.     ++x;
  576.   y=0;
  577.  
  578.   while (line[y++] = line[x++])
  579.     ;
  580.  
  581.   return;
  582. }
  583.  
  584. int HTLoadExtensionsConfigFile (char *fn)
  585. {
  586.   char l[MAX_STRING_LEN],w[MAX_STRING_LEN],*ct;
  587.   FILE *f;
  588.   int x, count = 0;
  589.  
  590.   if (TRACE)
  591.     fprintf (stderr, "Loading extensions config file '%s'\n",
  592.          fn);
  593.  
  594.   if(!(f = fopen(fn,"r")))
  595.     {
  596.       if (TRACE)
  597.     fprintf (stderr, "Could not open extensions config file '%s'\n",fn);
  598.       return -1;
  599.     }
  600.  
  601.   while(!(getline(l,MAX_STRING_LEN,f)))
  602.     {
  603.       getword(w,l,' ','\t');
  604.       if(l[0] == '\0' || w[0] == '#')
  605.     continue;
  606.       ct = (char *)malloc(sizeof(char) * (strlen(w) + 1));
  607.       strcpy(ct,w);
  608.  
  609.       while(l[0])
  610.     {
  611.       getword(w,l,' ','\t');
  612.       if(w[0] && (w[0] != ' '))
  613.         {
  614.           char *ext = (char *)malloc(sizeof(char) * (strlen(w)+1+1));
  615.  
  616.           for(x=0; w[x]; x++)
  617.         ext[x+1] = TOLOWER(w[x]);
  618.           ext[0] = '.';
  619.           ext[strlen(w)+1] = 0;
  620.  
  621.           if (TRACE)
  622.         fprintf (stderr, "SETTING SUFFIX '%s' to '%s'\n", ext, ct);
  623.  
  624.           HTSetSuffix (ext, ct, "binary", 1.0);
  625.           count++;
  626.  
  627.           free (ext);
  628.         }
  629.     }
  630.       free(ct);
  631.     }
  632.  
  633.   fclose(f);
  634.  
  635.   return count;
  636. }
  637.